<template>
  <div class="command__wrapper_container" v-show="visible">
    <el-container>
      <el-header :height="'45'">
        <svg-icon icon-class="table"></svg-icon>
        巡护上报
        <span class="el-icon-circle-close" @click="handleCloseDialog"></span>
      </el-header>
      <el-main>
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"
                 :label-position="'left'" label-width="68px">
          <el-form-item label="案件类型" prop="evtType">
            <el-select v-model="queryParams.evtType" placeholder="请选择案件类型" clearable size="small" style="width: 180px !important;">
              <el-option
                v-for="dict in evtTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="案件来源" prop="evtSource">
            <el-select v-model="queryParams.evtSource" placeholder="请选择案件来源" clearable size="small" style="width: 192px !important" :disabled="true">
              <el-option
                v-for="dict in evtSourceOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="违法、违规信息" prop="violation" label-width="110px" :style="'width:60%'">
            <treeselect v-model="queryParams.violation" :options="violationOptions" :show-count="true"
                        placeholder="请选择违法、违规信息" style="width:210px;"/>
          </el-form-item>
          <el-form-item label="管辖区" prop="areaName" :style="'width:35%'">
            <el-select v-model="queryParams.areaName" placeholder="请选择管辖区" clearable size="medium" style="width: 125px !important">
              <el-option
                v-for="dict in areaNameOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="举报时间" prop="reporterTime">
            <el-date-picker clearable size="small" style="width: 180px !important"
                            v-model="queryParams.reporterTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择举报时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="举报内容" prop="evtContent">
            <el-input  style="width: 192px !important"
                       v-model="queryParams.evtContent"
                       placeholder="请输入查询内容"
                       clearable
                       size="small"
            />
          </el-form-item>
          <el-form-item style="width: 100%;text-align: center;">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="eventList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column label="主建id" align="center" prop="id" v-if="false"/>
          <el-table-column label="定位" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="showPoint(scope.row)"
              >定位
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="案件号" align="center" class-name="small-padding fixed-width" width="150">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="showEvt(scope.row)"
              >{{ scope.row.evtCode }}
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="违法、违规信息" align="center" prop="violationName" width="180"/>
          <el-table-column label="案件地点" align="center" prop="evtAddress" show-overflow-tooltip/>
<!--          <el-table-column label="举报时间" align="center" prop="reporterTime" width="180">-->
<!--          </el-table-column>-->
          <el-table-column label="案件内容" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-html="scope.row.evtContent">{{scope.row.evtContent}}</span>
            </template>
          </el-table-column>
          <!--      <el-table-column label="事发现场图片" align="center" class-name="small-padding fixed-width">-->
          <!--        <template slot-scope="scope">-->
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-document"-->
          <!--            @click="showImage(scope.row)"-->
          <!--            v-hasPermi="['frontierEvent:event:edit']"-->
          <!--          >查看-->
          <!--          </el-button>-->
          <!--        </template>-->
          <!--      </el-table-column>-->
          <el-table-column label="信息核实" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-row v-if="scope.row.isverify === '1'">
                {{'已核实'}}
              </el-row>
              <el-row v-else v-else-if="scope.row.evtState === '4'">
                {{'已作废'}}
              </el-row>
              <el-row v-else>
                {{'待核实'}}
              </el-row>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          small
          layout="total,prev, pager, next"
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-main>
    </el-container>
    <el-dialog :visible.sync="dialogVisible" title="预览" class="imgss" height="800" z-index="20">
      <viewer :images="imgs">
        <img v-for="src in imgs" :key="src.url" :src="src.url">
      </viewer>
    </el-dialog>
  </div>
</template>

<script>
  import {
    queryAuditListForMap
  } from '@/api/frontierEvent/event'

  import {treeselect} from '@/api/basicInformation/violationType'
  import Treeselect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  import Vue from 'vue'
  import Viewer from 'v-viewer'
  import 'viewerjs/dist/viewer.css'

  Vue.use(Viewer)
  Viewer.setDefaults({
    Options: {
      'inline': false,
      'button': true,
      'navbar': true,
      'title': true,
      'toolbar': true,
      'tooltip': true,
      'movable': true,
      'zoomable': true,
      'rotatable': true,
      'scalable': true,
      'transition': true,
      'fullscreen': true,
      'keyboard': true,
      'url': 'data-source',
      'zIndexInline': 9999
    }
  })
  export default {
    name: 'Event',
    components: {Treeselect},
    data() {
      return {
        isShowMap: false,
        objectForm: {},
        userId: 0,
        dialogVisible: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 案件信息表格数据
        eventList: [],
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        openDetail: false,
        // 案件类型字典
        evtTypeOptions: [],
        // 案件来源字典
        evtSourceOptions: [],
        // 案件状态字典
        evtStateOptions: [],
        // 违法、违规信息字典
        violationOptions: [],
        // 管辖区字典
        areaNameOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 5,
          evtType: undefined,
          evtSource: '3',
          violation: undefined,
          areaName: undefined,
          reporterTime: undefined,
          orderByColumn: 'reporterTime',
          isAsc: 'desc'
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          evtSource: [
            { required: true, message: '案件来源不能为空', trigger: 'change' }
          ],
          evtState: [
            { required: true, message: '案件状态不能为空', trigger: 'change' }
          ]
        },
        imgs: [
          {
            url: 'http://192.168.20.113:8080/files/view?id=60b0996d78098f1deff7465c',
            title: '图片1'
          },
          {
            url: 'http://192.168.20.113:8080/files/view?id=60b0996d78098f1deff7465c',
            title: '图片2'
          }
        ],
        fileUrl: process.env.VUE_APP_BASE_API + '/files/view?id=', // 上传的图片服务器地址,
        isTool: false,
        row: {},
        caseDetail: {}
      }
    },
    props: {
      value: {
        type: String,
        default: 'http://192.168.20.113:8080/files/view?id=60b0996d78098f1deff7465c'
      },
      visible: {
        type: Boolean,
        default: false
      }
    },
    created() {
      this.getList()
      this.getTreeselect()
      this.getDicts('evt_type').then(response => {
        this.evtTypeOptions = response.data
      })
      this.getDicts('evt_source').then(response => {
        this.evtSourceOptions = response.data
      })
      this.getDicts('evt_state').then(response => {
        this.evtStateOptions = response.data
      })
      // this.getDicts('evt_violation_type').then(response => {
      //   this.violationOptions = response.data
      // })
      this.getDicts('evt_area').then(response => {
        this.areaNameOptions = response.data
      })
    },
    methods: {
      getTreeselect() {
        treeselect().then(response => {
          this.violationOptions = response.data
        })
      },
      handleOpenDialog() {
        this.getList()
      },
      handleCloseDialog() {
        this.$emit('close')
      },
      showImage(row) {
        this.imgs = []
        const _this = this
        if (row.attachIds && row.attachIds.length > 0) {
          row.attachIds.forEach(item => {
            this.imgs.push({
              url: _this.fileUrl + item.fileId,
              title: item.fileName
            })
          })
          this.dialogVisible = true
          // this.$viewer.show()
        }
      },
      /** 查询案件信息列表 */
      getList() {
        this.loading = true
        queryAuditListForMap(this.queryParams).then(response => {
          this.eventList = response.rows
          this.total = response.total
          this.$emit('showAppAlarmNum', response.total)
          this.loading = false
        })
      },
      // 案件类型字典翻译
      evtTypeFormat(row, column) {
        return this.selectDictLabel(this.evtTypeOptions, row.evtType)
      },
      // 案件来源字典翻译
      evtSourceFormat(row, column) {
        return this.selectDictLabel(this.evtSourceOptions, row.evtSource)
      },
      // 案件状态字典翻译
      evtStateFormat(row, column) {
        return this.selectDictLabel(this.evtStateOptions, row.evtState)
      },
      // 违法、违规信息字典翻译
      violationFormat(row, column) {
        return this.selectDictLabel(this.violationOptions, row.violation)
      },
      // 管辖区字典翻译
      areaNameFormat(row, column) {
        return this.selectDictLabel(this.areaNameOptions, row.areaName)
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      showPoint(row) {
        this.$emit('showAppPoint', row)
      },
      showEvt(e) {
        const detail = {}
        detail.target = 'app'
        detail.item = e
        this.$emit('ShowDetail', detail)
      }
    }
  }
</script>
<style scoped lang="scss">
  @import '../style/main';

  .imgss img {
    width: 250px !important;
    height: 250px !important;
    /*float: left;*/
  }
  ::v-deep .el-form-item .el-select .el-input{
    width: inherit !important;
  }
</style>
